﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using agsXMPP.protocol.client;
using Mammoth.Entities;
using Mammoth.Services;

namespace Mammoth.Mocks
{
    public class GTalkServiceMock : IGTalkService
    {
        public event EventHandler<Events.ServiceErrorEventArgs> Error;
        public event EventHandler<Events.ServiceEventArgs> FriendListLoad;
        public event EventHandler<Events.ServiceEventArgs> Login;
        public event EventHandler<Events.ServiceEventArgs> Logout;
        public event EventHandler<Events.ServiceMessageEventArgs> Message;
        public event EventHandler<Events.SubscriptionRequestEventArgs> SubscriptionRequest;
        public event EventHandler AccountListChange;

        public GTalkServiceMock()
        {
            AccountList = new List<AccountEntity>(
                new AccountEntity[2]{
                    new AccountEntity(){ Email = "valas.server@gmail.com", Password = "tos"},
                    new AccountEntity(){ Email = "valas.client@gmail.com", Password = "tos"},
                });
            BuddyList = new List<BuddyEntity>(
                new BuddyEntity[3]{
                    new BuddyEntity(){ Name = "Wayan", Email = "suyasa@yahoo.com", 
                        ServiceEmail = "valas.server@gmail.com", 
                        PresenceType= PresenceType.subscribe},
                    new BuddyEntity(){ Name = "Made", Email = "jono@yahoo.com", 
                        ServiceEmail = "valas.client@gmail.com"},
                    new BuddyEntity(){ Name = "Nyoman", Email = "wahyu@yahoo.com", 
                        ServiceEmail = "valas.server@gmail.com"},
                });
        }

        public IList<Entities.BuddyEntity> BuddyList { get; private set; }

        public IList<Entities.AccountEntity> AccountList { get; private set; }

        public void DoLogin(string email, string password)
        {
            var account = AccountList.FirstOrDefault(x => x.Email == email);
            if (account != null)
                account.State = AccountState.Login;
        }

        public void DoLogout(string serviceEmail)
        {
            var account = AccountList.FirstOrDefault(x => x.Email == serviceEmail);
            if (account != null)
                account.State = AccountState.Logoff;
        }

        public void ApproveSubscirption(string serviceEmail, string buddyEmail)
        {
            
        }

        public void SendMessage(string serviceEmail, string buddyEmail, string message)
        {
            
        }

        public void Subscribe(string serviceEmail, string buddyEmail)
        {
            
        }


        public void RemoveAccount(string serviceEmail)
        {
            var account = AccountList.FirstOrDefault(x => x.Email == serviceEmail);
            AccountList.Remove(account);
            if (AccountListChange != null)
                AccountListChange(this, new EventArgs());
        }


        public void BlockBuddy(string serviceEmail, string buddyEmail)
        {
            
        }


        public void LoginAll()
        {
            
        }


        public void AddAccount(string email, string password, bool isAutoLogin)
        {
            
        }
    }
}
